//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.bfsuolcomponents.file.service.impl;

import com.bfsuolcomponents.file.dao.FileManagerDAO;
import com.bfsuolcomponents.file.entity.FileManager;
import com.bfsuolcomponents.file.service.FileManagerService;
import com.bfsuolframework.core.service.ServiceSupport;
import com.bfsuolframework.core.utils.FileUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FileManagerServiceImpl extends ServiceSupport<FileManager> implements FileManagerService {
    @Autowired
    private FileManagerDAO fileManagerDAO;

    public FileManagerServiceImpl() {
    }

    public FileManagerDAO getDao() {
        return this.fileManagerDAO;
    }

    public boolean deleteFile(long id, String srcPath) {
        boolean flag = true;

        try {
            FileUtils.deleteFile(srcPath);
            this.getDao().delete(Long.valueOf(id));
        } catch (Exception var6) {
            flag = false;
        }

        return flag;
    }

    public FileInputStream getFileInputStream(long id, HttpServletRequest request) {
        FileManager fileManager = (FileManager)this.getDao().getById(Long.valueOf(id));
        String filePath = request.getSession().getServletContext().getRealPath("");
        filePath = filePath + fileManager.getFilePath();
        File file = new File(filePath);
        FileInputStream fis = null;

        try {
            fis = new FileInputStream(file);
        } catch (FileNotFoundException var9) {
            var9.printStackTrace();
        }

        return fis;
    }
}
